package model

import (
	"gorm.io/gorm"
	"smart-health-platforms/config"
	"time"
)

type MembershipRenewals struct {
	Id            int32          `gorm:"column:id;type:int;primaryKey;not null;" json:"id"`
	OrderNumber   string         `gorm:"column:order_number;type:varchar(255);comment:订单编号;not null;" json:"order_number"`         // 订单编号
	UserId        uint32         `gorm:"column:user_id;type:int UNSIGNED;comment:用户id;not null;" json:"user_id"`                   // 用户id
	RenewalDate   int32          `gorm:"column:renewal_date;type:int;comment:续费日期;not null;" json:"renewal_date"`                  // 续费日期
	ExpireDate    int32          `gorm:"column:expire_date;type:int;comment:到期日期;not null;" json:"expire_date"`                    // 到期日期
	Amount        uint64         `gorm:"column:amount;type:bigint UNSIGNED;comment:续费金额;not null;" json:"amount"`                  // 续费金额
	PaymentMethod uint8          `gorm:"column:payment_method;type:tinyint UNSIGNED;comment:支付方式;not null;" json:"payment_method"` // 支付方式
	Status        uint8          `gorm:"column:status;type:tinyint UNSIGNED;comment:支付状态 1：已支付 2未支付 3已完成;not null;" json:"status"` // 支付状态 1：已支付 2未支付 3已完成
	CreatedAt     time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt     time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt     gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (m *MembershipRenewals) TableName() string {
	return "membership_renewals"
}
func (m *MembershipRenewals) CreateMembershipRenewals() error {
	return config.DB.Create(&m).Error
}
func (m *MembershipRenewals) UpdateMembershipRenewals() error {
	return config.DB.Model(&MembershipRenewals{}).Where("order_number = ?", m.OrderNumber).Update("status", m.Status).Error
}
func (m *MembershipRenewals) UpdateMembershipRenewalsExpireDate() error {
	return config.DB.Model(&MembershipRenewals{}).Where("order_number = ?", m.OrderNumber).Update("expire_date", m.ExpireDate).Error
}
func (m *MembershipRenewals) GetMembershipRenewals() error {
	return config.DB.Model(&MembershipRenewals{}).Where("order_number = ?", m.OrderNumber).Find(&m).Error
}
